/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yinshi.fsm;

import java.util.ArrayList;

/**
 *
 * @author yinshi
 */
public class Group {

    private final ArrayList<State> states = new ArrayList<>();
    private boolean compiled = false;

    public Group() {
        states.add(new State(this, 0));
    }

    public State getEntryState() {
        return states.get(0);
    }

    public State newState() {
        State state = new State(this, states.size());
        return state;
    }

    void compile() {
        if (!compiled) {
            compiled = true;
            states.trimToSize();
        }
    }

    public State getState(int id) {
        return states.get(id);
    }

    public int numOfStates() {
        return states.size();
    }
}